//
//  MBProgressHUD+WYP.m
//  BeidouMall
//
//  Created by qie on 16/4/2.
//  Copyright © 2016年 qie. All rights reserved.
//

#import "MBProgressHUD+WYP.h"

@implementation MBProgressHUD (WYP)

+ (instancetype)showHUDAddedTo:(UIView *)view withText:(NSString *)text {
    
    if (view == nil) view = [[UIApplication sharedApplication] keyWindow];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = text;
    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
        hud.labelFont = [UIFont fontWithName:@"Bzdbt" size:10.0];
    } else {
        hud.labelFont = [UIFont boldSystemFontOfSize:16.0];
    }
    // 遮罩
    hud.dimBackground = NO;
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}

- (void)hideAfterDelay:(NSTimeInterval)delay {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self hide:YES];// 必须在主线程移除
    });
}

+ (void)showToast:(UIView *)view withText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{// 更新UI操作必须在主线程
        MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
        [view addSubview:hud];
        if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
            hud.detailsLabelFont = [UIFont fontWithName:@"Bzdbt" size:10.0];
        } else {
            hud.detailsLabelFont = [UIFont systemFontOfSize:15.0];
        }
        hud.detailsLabelText = text;
        
        hud.mode = MBProgressHUDModeText;
        [hud showAnimated:YES whileExecutingBlock:^{
            sleep(1);
        } completionBlock:^{
            [hud removeFromSuperview];
        }];
    });
}

+ (void)showToast:(UIView *)view withText:(NSString *)text withOffsetY:(CGFloat) y {
    dispatch_async(dispatch_get_main_queue(), ^{// 更新UI操作必须在主线程
        MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
        [view addSubview:hud];
        if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
            hud.detailsLabelFont = [UIFont fontWithName:@"Bzdbt" size:10.0];
        } else {
            hud.detailsLabelFont = [UIFont systemFontOfSize:15.0];
        }
        hud.detailsLabelText = text;
        hud.mode = MBProgressHUDModeText;
        hud.yOffset = y;
        [hud showAnimated:YES whileExecutingBlock:^{
            sleep(2);
        } completionBlock:^{
            [hud removeFromSuperview];
        }];
    });
}

@end
